package com.ccp.dev.im.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.poi.excel.Excel;
import com.ccp.dev.im.dao.ImSystemMessageDao;
import com.ccp.dev.im.model.ImSystemMessage;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 系统消息 信息操作服务类
 *
 * @author y
 * @date 2020-03-11 10:21:05
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ImSystemMessageService extends BaseService<ImSystemMessage> {

    @Resource
    private ImSystemMessageDao dao;

    public HSSFWorkbook exportExcel(Excel excel,QueryFilter queryFilter){
    List<ImSystemMessage> dataList = this.dao.queryAll(queryFilter);
        int startRow = 1;
        //给每一个单元格赋值
        for (ImSystemMessage data : dataList) {
        excel.cell(startRow, 0).value(data.getId());
        //excel.cell(startRow, 1).value(data.getMc());
        //可在赋值时，根据需求进行格式化
        //excel.cell(startRow, 2).value(DateFormatUtil.formatDate(data.getRq()));
        //excel.cell(startRow, 3).value(data.getSj());
        //excel.cell(startRow, 4).value(data.getTenantId());
        startRow++;
        }
        return excel.getWorkBook();
    }

    /**
     * 查询未读消息数量
     * @param map
     * @return
     */
    public int queryNotReadMsgNum(Map map){
        return this.dao.queryNotReadMsgNum(map);
    }


    /**
     * 查询未读消息
     * @param queryFilter
     * @return
     */
    public List<ImSystemMessage> queryByReceiveUser(QueryFilter queryFilter){
        return this.dao.queryByReceiveUser(queryFilter);
    }

    /**
     * 更新消息读取状态
     * @param map
     * @return
     */
    public int updateMsgReadStatus(Map map){
        return this.dao.updateMsgReadStatus(map);
    }

}
